package com.numbfish.ch01_ex01_bean_resister;

import com.numbfish.ch01_ex01_bean_resister.config.CustomConfig01Base;
import lombok.extern.slf4j.Slf4j;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.util.Arrays;

@SpringBootTest
@Slf4j

public class Ch01Ex01BeanResisterTestApp1Base {
    @Autowired
    private  ApplicationContext applicationContext;
    public final static ApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(CustomConfig01Base.class);

    @Test
    void contextLoads() {
        log.info("applicationContext = {}",applicationContext);
    }
    @Test
    void beanCount(){
        // 用户未定义任何类时的bean个数为 springBoot2.7 : 139
        // 用户未定义任何类时的bean个数为 springBoot3   : 152
        log.info("applicationContext default bean count= {}",applicationContext.getBeanDefinitionNames().length);
    }


    void outputTheBeanFromContext(Class<?> clazz){
        // 用户未定义任何类时的bean个数为152
        log.info("applicationContext get a bean  {} === {}",clazz,applicationContext.getBean(clazz));
    }
    @Test
    void getBeanTest(){
        int beanCount = annotationConfigApplicationContext.getBeanDefinitionCount();
        log.info("beanCount==={}",beanCount);
    }

    @Test
    void outputEachBean(){
        String[] names = annotationConfigApplicationContext.getBeanDefinitionNames();
        Arrays.stream(names).forEach(System.out::println);
    }
}
